org	07c00h

;BaseOfLoader		equ	 09000h	
;offsetOfLoader		equ	  0100h
;OffsetOfLoader		equ	  0h

%include "bootconst.inc"

jmp short LABEL_START

LABEL_START:
	mov ax,cs
	mov ds,ax
	mov es,ax
	mov ss,ax
	mov sp,07b00h
	
	mov	ax, 0600h		; AH = 6,  AL = 0h
	mov	bx, 0700h		; 黑底白字(BL = 07h)
	mov	cx, 0			; 左上角: (0, 0)
	mov	dx, 0184fh		; 右下角: (80, 50)
	int	10h			; int 10h
	
	
	
	mov ax,0000h	;显示osmsg
	push ax
	mov ax,OSMsg
	push ax
	mov word ax,11
	push ax
	call ShowStr
	add sp,6
	
	mov ax,cs		;ShowStr函数的int 10h中断会改变es的值
	mov es,ax		;Starting...
	mov ax,0100h
	push ax
	mov ax,StartMsg
	push ax
	mov word ax,11
	push ax
	call ShowStr
	add sp,6
	
	mov ax,cs		;show loading
	mov es,ax
	mov ax,0200h
	push ax
	mov ax,LoadMsg
	push ax
	mov word ax,10
	push ax
	call ShowStr
	add sp,6
	
	mov ax,cs		;show base and offset
	mov es,ax
	mov ax,0300h
	push ax
	mov ax,Loadadd
	push ax
	mov word ax,24
	push ax
	call ShowStr
	add sp,6
	

	
	;reboot floopy
	xor ah,ah
	xor dl,dl
	int 13h
	
	mov ax,BaseOfLoader
	mov es,ax
	mov ax,OffsetOfLoader
	mov bx,ax
	
	
	mov cl,2
	mov al,4
	mov dl,0
	mov dh,0
	mov ch,0
	mov ah,02h
	int 13h
	
	cmp  ah,0
	jne	ER

	mov ax,cs		;show load succ
	mov es,ax
	mov ax,0400h
	push ax
	mov ax,SuccMsg
	push ax
	mov word ax,13
	push ax
	call ShowStr
	add sp,6
	
	jmp BaseOfLoader:OffsetOfLoader
	
ER:
	mov ax,cs
	mov es,ax
	mov ax,0400h
	push ax
	mov ax,ErMsg
	push ax
	mov word ax,15
	push ax
	call ShowStr
	add sp,6
	jmp $
	
ShowStr:
	push bp
	mov bp,sp
	push ax
	push bx
	push cx
	push dx
	
	mov cx,word [bp + 4]	;字符个数
	mov ax,word [bp + 6]	;字符串首地址
	mov dx,word [bp + 8]	;显示位置
	mov bp,ax
	mov ax,01300h
	mov bx,0007h
	;mov dl,0
	int 10h
	
	pop dx
	pop cx
	pop bx
	pop ax
	pop bp
	ret
	
OSMsg:		db	"OS alpha   "
StartMsg:	db	"Starting..."
LoadMsg:	db	"Loading..."
Loadadd:	db 	"base=0x9000,offset=0x100"
SuccMsg:	db	"Loading succ!"
ErMsg:		db	"Loading failed!"

times	510 - ($ -$$) db 0
dw	0xaa55
